package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.SimpleDateFormat;

import flc.ast.R;
import flc.ast.bean.MyFileBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class VideoAdapter extends StkProviderMultiAdapter<MyFileBean> {

    public VideoAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new VideoProvider());
    }

    private boolean isEdit;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class VideoProvider extends BaseItemProvider<MyFileBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_video;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyFileBean bean) {
            Glide.with(getContext()).load(bean.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivVideoItemImg));
            baseViewHolder.setText(R.id.tvVideoItemName, FileUtils.getFileName(bean.getPath()));
            baseViewHolder.setText(R.id.tvVideoItemSize, ConvertUtils.byte2FitMemorySize(FileUtils.getFileLength(bean.getPath()), 0));
            baseViewHolder.setText(R.id.tvVideoItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean.getPath()), new SimpleDateFormat("MM/dd HH:mm")));
            if (isEdit) {
                if (bean.isSelected()){
                    baseViewHolder.setImageResource(R.id.ivVideoItemSel, R.drawable.xz);
                }else {
                    baseViewHolder.setImageResource(R.id.ivVideoItemSel, R.drawable.not_sel);
                }
            } else {
                baseViewHolder.setImageResource(R.id.ivVideoItemSel, R.drawable.bf);
            }
        }
    }

}
